package com.base.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.base.exception.BusinessException;
import com.base.model.CntrMovReq;
import com.base.service.ISimpleService;
import com.base.vo.Response;
import com.base.vo.ReturnCodeEnum;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @类描述：当没有请求地址时默认定向到这里
 * @创建人：wangdw
 * @创建时间：2018年11月6日 上午10:09:47
 */
@Api(tags = "首页")
@RestController
@RequestMapping("index")
public class IndexController extends BaseController {
    @Autowired
    private ISimpleService simpleService;
    
    @ApiOperation(value = "页面", code = 200, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @RequestMapping
    public ModelAndView index() {
        return new ModelAndView("index");
    }
    
    @ApiOperation(value = "查询所有数据", code = 200, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @GetMapping("/queryAll")
    public Response<List<CntrMovReq>> queryAll() {
        Response<List<CntrMovReq>> res = new Response<>();
        try {
            res.setData(simpleService.queryAll());
        } catch (Exception e) {
            res = new Response<>(ReturnCodeEnum.CODE_9999);
            BusinessException.error("IndexController.selectAll error>>>>>>>>>>>重大异常", e);
        }
        return res;
    }
}
